<template>
  <div class="app-container">

    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="playerQuery.name" placeholder="球员姓名"/>
      </el-form-item>

      <el-form-item>
        <el-input v-model="playerQuery.nation" placeholder="球员国家"/>
      </el-form-item>

      <el-form-item>
        <el-input v-model="playerQuery.position" placeholder="球员位置"/>
      </el-form-item>

      <el-form-item label="添加时间">
        <el-date-picker
          v-model="playerQuery.begin"
          type="datetime"
          placeholder="选择开始时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="playerQuery.end"
          type="datetime"
          placeholder="选择截止时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="getList()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>

    <!-- 表格 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="数据加载中"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="name" label="姓名" width="120" />

      <el-table-column prop="nation" label="国籍" width="120" />


      <el-table-column prop="position" label="位置" />

      <el-table-column prop="number" label="国家队号码"/>

      <el-table-column prop="createDate" label="添加时间" width="160"/>

      <!--    <el-table-column prop="sort" label="排序" width="60" />-->

      <el-table-column label="操作" width="400" align="center">
        <template slot-scope="scope">
          <router-link :to="'/player/save/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
          </router-link>
          <router-link :to="'/player/data/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">设置数据</el-button>
          </router-link>
          <router-link :to="'/player/show/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">能力分析</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />



  </div>
</template>
<script>
  // 引入js文件
  import player from '@/api/dbwork/player'
  export default {
    data(){ //定义变量和初始值
      return{
        list:null, // 查询之后返回的list
        page:1,
        limit:10,
        total:0,
        playerQuery:{}  // 封装的数据
      }
    },
    created() { //页面渲染之然执行
      this.getList()
    },
    methods:{
      // 创建具体的方法
      // 球员列表的方法
      getList(page = 1){
        this.page = page
        player.getPlayerListPage(this.page,this.limit,this.playerQuery)
        .then(response => {
            // console.log(response)
            this.list = response.data.rows
            this.total = response.data.total
        })
      },
      resetData(){
        this.playerQuery = {}
        this.getList()
      },
      removeDataById(id){

        this.$confirm('此操作将永久删除球员信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            player.deletePlayer(id)
            .then(response => {
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                });
                this.getList()
            })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });

      }
    }
  }
</script>
